package com.example.shouybl.ui;

import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.RadioGroup;

import com.example.shouybl.BaseApp;
import com.example.shouybl.R;
import com.example.shouybl.fragment.ActionFragment;
import com.example.shouybl.fragment.GameFragment;
import com.example.shouybl.fragment.GiftFragment;
import com.example.shouybl.fragment.GiftMobilFragment;
import com.example.shouybl.fragment.GiftWebFragment;
import com.example.shouybl.fragment.MoneyFragment;
import com.example.shouybl.fragment.MyFragment;
import com.example.shouybl.utils.AppManager;
import com.example.shouybl.utils.FragmentTabUtils;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends BaseActivity implements FragmentTabUtils.OnRgsExtraCheckedChangedListener {

    private List<Fragment> fragmentList;
    private RadioGroup rg;
    private long time;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        getSupportActionBar().hide();
        initView();
    }

    private void initView() {
        rg = (RadioGroup) findViewById(R.id.main_rg);
        fragmentList = new ArrayList<Fragment>();
        fragmentList.add(new GiftFragment());
        fragmentList.add(new ActionFragment());
        fragmentList.add(new GameFragment());
        fragmentList.add(new MoneyFragment());
        fragmentList.add(new MyFragment());

        FragmentTabUtils fragmentTabUtils = new FragmentTabUtils(getSupportFragmentManager(), fragmentList, R.id.main_fragment_container, rg, this);

    }

    @Override
    public void onBackPressed() {
        long currentTime = System.currentTimeMillis();
        if (currentTime - time > 2 * 1000) {
            time = currentTime;
            BaseApp.getInstance().showToast("再点一次退出程序");
        } else {
            AppManager.getAppManager().AppExit(BaseApp.getInstance());
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        BaseApp.getInstance().unegisterNetworkStateReceiver();
    }

    @Override
    public void OnRgsExtraCheckedChanged(RadioGroup radioGroup, int checkedId, int index) {

    }


}
